package com.xbongbong.saas.enums.business;

import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.enums.ScreenTypeEnum;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.saas.enums.SetTypeEnum;
import com.xbongbong.saas.enums.ShowTypeEnum;
import com.xbongbong.saas.enums.VisibleRangeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * 产品枚举类
 * 注意：
 * 1.强制：attr的值一经刷入数据库，就不允许改变（比如text_1不允许改为text_12，即使不冲突，因为后续会根据枚举中saasAttr和attr的对应关系来获取解释）
 * 2.强制：属性修饰必须为private，比如private String attr（后续反射获取属性时会依赖到）
 * 3.强制：属性的名称必须和FieldAttrEntity实体中的属性一致，不然无法赋值过去
 *
 * @author chaoxiong.lei
 * @date 2019/1/14 13:57
 */
@Getter
public enum ProductEnum {
    // 产品模板设计界面需要展示的字段
    // 基本信息
    BASE_INFO("other_1", "enum.product.attrName.base_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 10000, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    NAME("text_1", "enum.product.attrName.name", "name", FieldTypeEnum.TEXT.getType(), SetTypeEnum.DISABLE_OPEN.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9990, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SERIALNO("serialNo", "enum.product.attrName.serialno", "serialNo", FieldTypeEnum.SERIALNO.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9980, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PRODUCT_NO("text_2", "enum.product.attrName.product_no", "productNo", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9970, 1, 1, ScreenTypeEnum.SCREEN_GROUP.getType()),
    BARCODE("text_3", "enum.product.attrName.barcode", "barcode", FieldTypeEnum.TEXT.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9960, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PRODUCT_IMGS("file_1", "enum.product.attrName.product_imgs", "productImgs", FieldTypeEnum.IMAGE.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9950, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CATEGORY_ID("num_13", "enum.product.attrName.category_id", "categoryId", FieldTypeEnum.CATEGORY_ID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9940, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    LABEL("array_31", "enum.product.attrName.label", "label", FieldTypeEnum.LABEL.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9935, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    ENABLE_MULTI_UNIT("num_61","enum.product.attrName.enable_multi_unit","enableMultiUnit",FieldTypeEnum.SWITCH.getType(), 1, 0, 1, ShowTypeEnum.LIST_DETAIL.getCode(), 9762, 0, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UNIT("text_8", "enum.product.attrName.unit", "productUnit", FieldTypeEnum.COMBO.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9930, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    PRICE("num_1", "enum.product.attrName.price", "price", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9920, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    COST("num_2", "enum.product.attrName.cost", "cost", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9910, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    STOCK("num_12", "enum.product.attrName.stock", "stock", FieldTypeEnum.NUM.getType(), 3, 0, 0, ShowTypeEnum.LIST_DETAIL.getCode(), 9900, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    INSTRUCTION("text_7", "enum.product.attrName.instruction", "instruction", FieldTypeEnum.RICH_TEXT_EDITOR.getType(), 3, 0, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9890, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    VISBLE_DEPT(VisibleRangeEnum.VISIBLE_DEPT.getAttr(), VisibleRangeEnum.VISIBLE_DEPT.getAttrName(), VisibleRangeEnum.VISIBLE_DEPT.getSaasAttr(), VisibleRangeEnum.VISIBLE_DEPT.getFieldType(), SetTypeEnum.DISABLE_NONE.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9880, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    VISBLE_USER(VisibleRangeEnum.VISIBLE_USER.getAttr(), VisibleRangeEnum.VISIBLE_USER.getAttrName(), VisibleRangeEnum.VISIBLE_USER.getSaasAttr(), VisibleRangeEnum.VISIBLE_USER.getFieldType(), SetTypeEnum.DISABLE_NONE.getCode(), 1, 0, ShowTypeEnum.ALL.getCode(), 9870, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ATTACHMENT("file_2", "enum.product.attrName.attachment", "attachment", FieldTypeEnum.UPLOAD.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9860, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    SPECIFICATION_INFO("other_10", "enum.product.attrName.specification_info", "baseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9850, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // SPECIFICATION存的是0,1  等价以前的advancededMode，1是高级规格，0是单规格,
    SPECIFICATION("text_5", "enum.product.attrName.specification", "specification", FieldTypeEnum.SPECIFICATION.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9840, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    WAREHOUSE_INFO("other_9", "enum.product.attrName.warehouse_info", "warehouseInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9830, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    WAREHOUSE("text_70", "enum.product.attrName.warehouse", "warehouse", FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9820, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    STOCK_INFO("other_8", "enum.product.attrName.stock_info", "stockInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9810, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    IS_NOTIFY("num_8", "enum.product.attrName.is_notify", "isNotify", FieldTypeEnum.SWITCH.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 0, ShowTypeEnum.ALL.getCode(), 9800, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),

    STOCK_NOTIFY("subForm_3","enum.product.attrName.stock_notify","stockNotify",FieldTypeEnum.SUB_FORM.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 0, 1, ShowTypeEnum.ALL.getCode(), 9790, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),


    // 关联信息
    ASSOCIATED_INFO("other_2", "enum.product.attrName.associated_info", "associatedInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9780, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SUPPLIER("text_9", "enum.product.attrName.supplier", "supplier", FieldTypeEnum.LINK_BUSINESS_MULTI.getType(), 3, 0, 0, ShowTypeEnum.ALL.getCode(), 9770, 1, 0, ScreenTypeEnum.SCREEN_SEARCH.getType()),
    BATCH_SHELF_LIFE_MANAGEMENT("other_19","enum.product.attrName.batch_shelf_life_management","batchShelfLifeManagement",FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 1, ShowTypeEnum.EDIT_DETAIL.getCode(), 9761, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ENABLE_BATCH_SHELF_LIFE("num_36","enum.product.attrName.enable_batch_shelf_life","enableBatchShelfLife",FieldTypeEnum.SWITCH.getType(), 1, 0, 1, ShowTypeEnum.ALL.getCode(), 9762, 0, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SHELF_LIFE_DAYS("num_37", "enum.product.attrName.shelf_life_days", "shelfLifeDays", FieldTypeEnum.NUM.getType(), 3, 0, 1, ShowTypeEnum.ALL.getCode(), 9640, 0, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    EXPIRATION_ALERT_DAYS("num_38", "enum.product.attrName.expiration_alert_days", "expirationAlertDays", FieldTypeEnum.NUM.getType(), 3, 0, 1, ShowTypeEnum.ALL.getCode(), 9763, 0, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    SERIAL_NUMBER_MANAGEMENT("other_20","enum.product.attrName.serial_number_management","serialNumberManagement",FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 1, ShowTypeEnum.EDIT_DETAIL.getCode(), 9764, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ENABLE_SERIAL_NUMBER("num_39","enum.product.attrName.enable_serial_number","enableSerialNumber",FieldTypeEnum.SWITCH.getType(), 1, 0, 1, ShowTypeEnum.ALL.getCode(), 9765, 0, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 系统信息
    SYSTEM_INFO("other_3", "enum.product.attrName.system_info", "systemInfo", FieldTypeEnum.SEPARATOR.getType(), SetTypeEnum.DISABLE_REPEAT.getCode(), 1, 0, ShowTypeEnum.EDIT_DETAIL.getCode(), 9760, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    CREATOR_ID("creatorId", "enum.product.attrName.creator_id", "creatorId", FieldTypeEnum.CREATORID.getType(), 1, 0, 0, ShowTypeEnum.ALL.getCode(), 9750, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    ADD_TIME("addTime", "enum.product.attrName.add_time", "addTime", FieldTypeEnum.ADDTIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9740, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    UPDATE_TIME("updateTime", "enum.product.attrName.update_time", "updateTime", FieldTypeEnum.UPDATETIME.getType(), 1, 1, 0, ShowTypeEnum.ALL.getCode(), 9730, 1, 0, ScreenTypeEnum.SCREEN_GROUP.getType()),
    // 上架时间
    ONLINE_TIME("date_20", "enum.product.attrName.online_time", "onlineTime", FieldTypeEnum.DATETIME.getType(), 1, 0, 0, ShowTypeEnum.LIST_DETAIL.getCode(), 9727, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    // 模板设计界面不需要展示的字段,
    // SPECIFICATION_LINK_TEXT字段存的是产品具体的规格
    // 销量
    SALES("num_62", "enum.product.attrName.sales", "sales", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9725, 0, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SPECIFICATION_LINK_TEXT("text_10", "enum.product.attrName.specification_link_text", "specificationLinkText", FieldTypeEnum.TEXT.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9720, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SUPPLIER_LINK_TEXT("text_11", "enum.product.attrName.supplier_link_text", "supplierLinkText", FieldTypeEnum.TEXTAREA.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9710, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    WAREHOUSE_LINK_TEXT("text_69","enum.product.attrName.warehouse_link_text","warehouseLinkText",FieldTypeEnum.TEXTAREA.getType(),1, 0, 1, ShowTypeEnum.NONE.getCode(), 9700, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    PARENT_ID("num_3", "enum.product.attrName.parent_id", "parentId", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9690, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    THUMBNAIL("file_3", "enum.product.attrName.thumbnail", "thumbnail", FieldTypeEnum.IMAGE.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9680, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ONLINE("num_4", "enum.product.attrName.online", "online", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9670, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SHOW_PRICE("num_5", "enum.product.attrName.show_price", "showPrice", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9660, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    SHOW_COST("num_6", "enum.product.attrName.show_cost", "showCost", FieldTypeEnum.COMBO_NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9650, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ORI_STOCK("num_7", "enum.product.attrName.ori_stock", "oriStock", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9640, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    STOCK_UPPER_LIMIT("num_9", "enum.product.attrName.stock_upper_limit", "stockUpperLimit", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9630, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    STOCK_LOWER_LIMIT("num_10", "enum.product.attrName.stock_lower_limit", "stockLowerLimit", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9620, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    TEMP_STOCK("num_11", "enum.product.attrName.temp_stock", "tempStock", FieldTypeEnum.NUM.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9610, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ENABLE_SKU("num_40","enum.product.attrName.enable_sku","enableSKU",FieldTypeEnum.SWITCH.getType(), 1, 0, 1, ShowTypeEnum.NONE.getCode(), 9600, 1, 0, ScreenTypeEnum.SCREEN_OFF.getType()),
    ;

    /**
     * 英文名称
     */
    private String attr;
    /**
     * 中文名称
     */
    private String attrName;
    /**
     * 对应saas中的attr
     */
    private String saasAttr;
    /**
     * 字段类型，详见
     *
     * @see com.xbongbong.paas.enums.FieldTypeEnum
     */
    private Integer fieldType;
    /**
     * 重命名、判重、启用必填等权限
     * 1.重命名+字段权限
     * 2.重命名+字段权限+查重
     * 3.重命名+字段权限+启用、必填
     * 4.重命名+字段权限+查重+启用、必填
     * 注：pro中启用和必填是同一个权限，同时启用或同时关闭
     */
    private Integer setType;
    /**
     * 模板设计阶段字段是否允许编辑
     * 1：允许编辑
     * 0：不允许编辑
     */
    private Integer designEditable;
    /**
     * 字段是否显示在模板设计界面
     * 1：不显示
     * 0：显示
     */
    private Integer editHide;
    /**
     * 字段在各个界面（新建、编辑、列表、详情）的展现形式
     * 详见
     *
     * @see com.xbongbong.saas.enums.ShowTypeEnum
     */
    private Integer showType;
    /**
     * 字段在模板设计界面的排序
     * 建议不要用连续的数字，可以用等差数列，以防以后在两个字段之间加入新字段
     */
    private Integer sort;
    /**
     * 字段在各个界面是否可见(启用)
     * 1：可见
     * 0：不可见
     * 注：字段在具体页面的可见性需要用属性和showType联合判断，在visible=1的情况下判断showType
     */
    private Integer visible;
    /**
     * 字段是否必填
     * 1：必填
     * 0：不必填
     */
    private Integer required;
    /**
     * 筛选类型
     * 1：可筛选
     * 2：不可筛选
     */
    private Integer screenType;

    ProductEnum(String attr, String attrName, String saasAttr, Integer fieldType, Integer setType, Integer designEditable,
                Integer editHide, Integer showType, Integer sort, Integer visible, Integer required, Integer screenType) {
        this.attr = attr;
        this.attrName = attrName;
        this.saasAttr = saasAttr;
        this.fieldType = fieldType;
        this.setType = setType;
        this.designEditable = designEditable;
        this.editHide = editHide;
        this.showType = showType;
        this.sort = sort;
        this.visible = visible;
        this.required = required;
        this.screenType = screenType;
    }

    /**
     * 对data内的字段拼上“data.”
     *
     * @param cache
     * @return java.lang.String
     * @author 徐俊杰
     * @date 2019/3/6 10:13
     * @since v1.0
     */
    public static String getAttrConnectData(ProductEnum cache) {
        return "data." + cache.getAttr();
    }

    /**
     * 获取es查询、聚合字段
     *
     * @param cache 当前枚举对象
     * @return java.lang.String 处理后的聚合字段
     * @author 徐俊杰
     * @date 2019/3/6 10:15
     * @since v1.0
     */
    public static String getEsAttr4Keyword(ProductEnum cache) {
        FieldTypeEnum fieldTypeEnum = FieldTypeEnum.getFieldTypeEnum(cache.fieldType);
        //字段类型为text，或者字段在es内的类型时text，则需要在后面拼上“.keyword”
        boolean flag = fieldTypeEnum == FieldTypeEnum.TEXT || "text".equals(fieldTypeEnum.getEsalias());
        if (flag) {
            return "data." + cache.getAttr() + ".keyword";
        }
        return "data." + cache.getAttr();
    }

    public static List<JSONObject> getWaitTabHeadd() {
        JSONObject radioCheck = new JSONObject();
        radioCheck.put("prop", FieldTypeEnum.HEAD_RADIO_GROUP.getAlias());
        radioCheck.put("fieldType", FieldTypeEnum.HEAD_RADIO_GROUP.getType());
        radioCheck.put("label", FieldTypeEnum.HEAD_RADIO_GROUP.getDescription());
        JSONObject groupCheck = new JSONObject();
        groupCheck.put("prop", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getAlias());
        groupCheck.put("fieldType", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getType());
        groupCheck.put("label", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getDescription());
        JSONObject image = new JSONObject();
        image.put("prop", "productThumnail");
        image.put("fieldType", ProductEnum.PRODUCT_IMGS.fieldType);
        image.put("label", ProductEnum.PRODUCT_IMGS.getAttrName());
        JSONObject productName = new JSONObject();
        productName.put("prop", "productName");
        productName.put("fieldType", ProductEnum.NAME.fieldType);
        productName.put("label", ProductEnum.NAME.getAttrName());
        JSONObject productNo = new JSONObject();
        productNo.put("prop", "productNo");
        productNo.put("fieldType", ProductEnum.PRODUCT_NO.fieldType);
        productNo.put("label", ProductEnum.PRODUCT_NO.getAttrName());
        JSONObject spec = new JSONObject();
        spec.put("prop", "productSpec");
        spec.put("fieldType", ProductEnum.SPECIFICATION.fieldType);
        spec.put("label", ProductEnum.SPECIFICATION.getAttrName());
        JSONObject num = new JSONObject();
        num.put("prop", "productNum");
        num.put("fieldType", ProductEnum.STOCK.fieldType);
        num.put("label", I18nMessageUtil.getMessage(I18nStringConstant.OUT_OF_STOCK_NUM));
        JSONObject unit = new JSONObject();
        unit.put("prop", "productUnit");
        unit.put("fieldType", ProductEnum.UNIT.fieldType);
        unit.put("label", ProductEnum.UNIT.getAttrName());
        return Arrays.asList(radioCheck, groupCheck, image, productName, productNo, spec, num, unit);
    }

    public static List<JSONObject> getWaitStockTabHeadd(Integer subBusinessType) {
        JSONObject groupCheck = new JSONObject();
        groupCheck.put("prop", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getAlias());
        groupCheck.put("fieldType", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getType());
        groupCheck.put("label", FieldTypeEnum.HEAD_CHECKBOX_GROUP.getDescription());
        JSONObject productThumnail = new JSONObject();
        productThumnail.put("prop", "productThumnail");
        productThumnail.put("fieldType", ProductEnum.PRODUCT_IMGS.fieldType);
        productThumnail.put("label", ProductEnum.PRODUCT_IMGS.getAttrName());

        JSONObject productName = new JSONObject();
        productName.put("prop", "productName");
        productName.put("fieldType", ProductEnum.NAME.fieldType);
        productName.put("label", ProductEnum.NAME.getAttrName());

        JSONObject productNo = new JSONObject();
        productNo.put("prop", "productNo");
        productNo.put("fieldType", ProductEnum.PRODUCT_NO.fieldType);
        productNo.put("label", ProductEnum.PRODUCT_NO.getAttrName());

        JSONObject specification = new JSONObject();
        specification.put("prop", "specification");
        specification.put("fieldType", ProductEnum.SPECIFICATION.fieldType);
        specification.put("label", ProductEnum.SPECIFICATION.getAttrName());

        JSONObject unit = new JSONObject();
        unit.put("prop", "unit");
        unit.put("fieldType", ProductEnum.UNIT.fieldType);
        if (Objects.equals(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(), subBusinessType)){
            unit.put("label", WaitInstockEnum.UNIT.getAttrName());
        }
        if (Objects.equals(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), subBusinessType)){
            unit.put("label", WaitOutstockEnum.UNIT.getAttrName());
        }

        JSONObject productNum = new JSONObject();
        productNum.put("prop", "productNum");
        productNum.put("fieldType", ProductEnum.STOCK.fieldType);
        if (Objects.equals(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode(), subBusinessType)){
            productNum.put("label", WaitInstockEnum.STOCK.getAttrName());
        }
        if (Objects.equals(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), subBusinessType)){
            productNum.put("label", WaitOutstockEnum.WAIT_OUTSTOCK_NUM.getAttrName());
        }


        JSONObject stockNum = new JSONObject();
        if (Objects.equals(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), subBusinessType)){
            stockNum.put("prop", "stock");
            stockNum.put("fieldType", ProductEnum.STOCK.fieldType);
            stockNum.put("label", ProductEnum.STOCK.getAttrName());
        }

        JSONObject memo = new JSONObject();
        memo.put("prop", "memo");
        memo.put("fieldType", WaitInstockEnum.MEMO.getFieldType());
        memo.put("label", WaitInstockEnum.MEMO.getAttrName());

        if (Objects.equals(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode(), subBusinessType)){
            return Arrays.asList(groupCheck, productThumnail, productName, productNo, specification, unit , productNum,stockNum, memo);
        }

        return Arrays.asList(groupCheck, productThumnail, productName, productNo, specification, unit , productNum, memo);

    }

    /**
     * app端详情默认标题显示字段
     *
     * @return List
     * @author GuoJun.HU
     * @date 2019/4/8 19:21
     * @since V1.0
     */
    public static List<Object> getTitleAttrList() {
        return Collections.singletonList(NAME);
    }

    /**
     * 把传入的字段（类型为LINK_BUSINESS_SINGLE）的转为其隐藏字段
     * @param attr 字段名
     * @return java.lang.String
     * @author zcp
     * @date 2019/7/4 15:31
     * @since v1.0
     * @version v1.0
     */
    public static String changeToHide4Link(String attr) {
        if (Objects.equals(attr, SUPPLIER.attr)) {
            return SUPPLIER_LINK_TEXT.attr;
        }
        return attr;
    }

    /**
     * 默认摘要
     *
     * @author long.rao
     * @date 2019-07-11 19:00
     */
    public static List<Object> getSummaryAttrList() {
        return Arrays.asList(SERIALNO, SPECIFICATION, STOCK);
    }

    public static boolean linkAttrCanShow(String attr) {
        return Objects.equals(attr, NAME.getAttr()) || Objects.equals(attr, SERIALNO.getAttr()) || Objects.equals(attr, PRODUCT_IMGS.getAttr()) || Objects.equals(attr, SPECIFICATION.getAttr()) || Objects.equals(attr, BARCODE.getAttr());
    }

    public static boolean linkAttrNotShow(String attr) {
        return Objects.equals(attr, STOCK_NOTIFY.getAttr()) || Objects.equals(attr, VISBLE_DEPT.getAttr()) || Objects.equals(attr, VISBLE_USER.getAttr());
    }
    public String getAttrName() {
        return I18nMessageUtil.getMessage(attrName);
    }

    public static String getI18nValue(String value) {
        return I18nMessageUtil.getMessage(value);
    }

    public static ProductEnum getByAttr(String alias) {
        for (ProductEnum cacheCode : values()) {
            if (cacheCode.getAttr().equals(alias)) {
                return cacheCode;
            }
        }
        return null;
    }
}
